package com.ruoyi.instrumentation.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.instrumentation.domain.UsageDetails;
import com.ruoyi.instrumentation.service.IUsageDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 使用明细Controller
 * 
 * @author hj
 * @date 2025-01-13
 */
@RestController
@RequestMapping("/details")
public class UsageDetailsController extends BaseController
{
    @Autowired
    private IUsageDetailsService usageDetailsService;

    /**
     * 查询使用明细列表
     */
    @RequiresPermissions("instrumentation:details:list")
    @GetMapping("/list")
    public TableDataInfo list(UsageDetails usageDetails)
    {
        startPage();
        List<UsageDetails> list = usageDetailsService.selectUsageDetailsList(usageDetails);
        return getDataTable(list);
    }

    /**
     * 导出使用明细列表
     */
    @RequiresPermissions("instrumentation:details:export")
    @Log(title = "使用明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UsageDetails usageDetails)
    {
        List<UsageDetails> list = usageDetailsService.selectUsageDetailsList(usageDetails);
        ExcelUtil<UsageDetails> util = new ExcelUtil<UsageDetails>(UsageDetails.class);
        util.exportExcel(response, list, "使用明细数据");
    }

    /**
     * 获取使用明细详细信息
     */
    @RequiresPermissions("instrumentation:details:query")
    @GetMapping(value = "/{usageId}")
    public AjaxResult getInfo(@PathVariable("usageId") Long usageId)
    {
        return success(usageDetailsService.selectUsageDetailsByUsageId(usageId));
    }

    /**
     * 新增使用明细
     */
    @RequiresPermissions("instrumentation:details:add")
    @Log(title = "使用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UsageDetails usageDetails)
    {
        return toAjax(usageDetailsService.insertUsageDetails(usageDetails));
    }

    /**
     * 修改使用明细
     */
    @RequiresPermissions("instrumentation:details:edit")
    @Log(title = "使用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UsageDetails usageDetails)
    {
        return toAjax(usageDetailsService.updateUsageDetails(usageDetails));
    }

    /**
     * 删除使用明细
     */
    @RequiresPermissions("instrumentation:details:remove")
    @Log(title = "使用明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usageIds}")
    public AjaxResult remove(@PathVariable Long[] usageIds)
    {
        return toAjax(usageDetailsService.deleteUsageDetailsByUsageIds(usageIds));
    }
}
